#include <bits/stdc++.h>
using namespace std;

struct Node{
    int a;
    int v;
    int d;
}node[100005];

int d[100005];
bool vis[100005];

struct KKK{
    int s;
    int e;
}kkk[100005];

bool vis2[100005];

int main()
{
    freopen("detect.in", "r", stdin);
    freopen("detect.out", "w", stdout);
    int t;
    scanf("%d", &t);
    while (t--) {
        memset(vis, 0, sizeof vis);
        memset(vis2, 0, sizeof vis2);
        int n, m, l, v;
        int sum = 0;
        int ans = 0;
        int pos = 0;
        int minn = m;
        int maxx = 1;
        int minnn = m + 1;
        //cin >> n >> m >> l >> v;
        scanf("%d %d %d %d", &n, &m, &l, &v);
        for (int i = 1; i <= n; i++) {
           // cin >> node[i].d >> node[i].v >> node[i].a;
            scanf("%d %d %d", &node[i].d, &node[i].v, &node[i].a);
        }
        for (int i = 1; i <= m; i++) {
           // cin >> d[i];
            scanf("%d", &d[i]);
        }
        for (int i = 1; i <= n; i++) {
            if (node[i].d > d[m]) {
                continue;
            }
            if (node[i].a == 0) {
                if (node[i].v > v) {
                  //  cout << i << endl;
                    sum++;
                    if (!vis[m]) {
                        vis[m] = true;
                        ans++;
                    }
                }
            } else if (node[i].a > 0) {
                int s = d[m] - node[i].d;
                double z = 1.0 * sqrt(1.0 * node[i].v * node[i].v + 2.0 * node[i].a * s);
                if (z - v > 0.000001) {
                    sum++;
                    if (!vis[m]) {
                        vis[m] = true;
                        ans++;
                    }
                    int q = m - 1;
                    while (q >= 1) {
                        int s = d[m] - node[i].d;
                        if (s < 0) {
                            break;
                        }
                        double z = 1.0 * sqrt(1.0 * node[i].v * node[i].v + 2.0 * node[i].a * s);
                        if (z - v > 0.000001) {
                            minnn = min(minnn, q);
                        }
                        q--;
                    }
                }
            } else if (node[i].a < 0) {
               int cnt = 1;
               while (d[cnt] < node[i].d) {
                   cnt++;
               }
               int s = d[cnt] - node[i].d;
               if (node[i].v * node[i].v + 2 * node[i].a * s > 0) {
                    double z = 1.0 * sqrt(1.0 * node[i].v * node[i].v + 2.0 * node[i].a * s);
                    if (z - v > 0.000001) {
                        sum++;
                        if (!vis[cnt]) {
                            pos++;
                            kkk[pos].s = cnt;
                            kkk[pos].e = cnt;
                            if (cnt < minn) {
                                minn = cnt;
                            }
                            cnt++;
                            while (cnt <= m) {
                                int ss = d[cnt] - node[i].d;
                                if (node[i].v * node[i].v + 2 * node[i].a * ss > 0) {
                                    double zz = 1.0 * sqrt(1.0 * node[i].v * node[i].v + 2.0 * node[i].a * ss);
                                    if (zz - v > 0.000001) {
                                        kkk[pos].e = cnt;
                                        if (cnt > maxx) {
                                            maxx = cnt;
                                        }
                                    } else {
                                        break;
                                    }
                                }
                                cnt++;
                            }
                        }
                    }
               }

            }
        }
        /*
        if (vis[m]) {
            for (int j = 1; j <= pos; j++) {
                if (kkk[j].e == m) vis2[j] = true;
            }
        }*/
        int q2 = 1;
        for (int i = minn; i <= maxx; i++) {
            for (int j = 1; j <= pos; j++) {
                if (!vis2[j]) {
                    if (i == kkk[j].e) {
                         q2 = max(q2, i);
                         vis2[j] = true;
                         ans++;
                         for (int k = 1; k <= pos; k++) {
                            if (!vis2[k]) {
                                 if (kkk[k].s <= i && kkk[k].e >= i) {
                                    vis2[k] = true;
                                }
                            }
                         }
                    }

                }
            }
        }
       if (minnn <= q2) ans--;
       //cout << sum << " " << m - ans << endl;
       printf("%d %d\n", sum, m - ans);
    }
    return 0;
}
